{extend name='common/_container'}
{block name="content"}
<div class="ibox float-e-margins">
	<div class="ibox-content">
		<div class="form-horizontal" id="CodeInfoForm">
			<div class="row">
				<div class="col-sm-12">
				<!-- form start -->
					<div class="form-group">
						<label class="col-sm-2 control-label">名称：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="vip_name" value="" name="vip_name" class="form-control" placeholder="请输入名称">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">价格：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="price" value="" name="price" class="form-control" placeholder="请输入价格">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">有效时长：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="days" value="" name="days" class="form-control" placeholder="请输入有效时长">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">交换次数：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="exchange_num" value="" name="exchange_num" class="form-control" placeholder="请输入交换次数">
						</div>
					</div>
					<div class="form-group layui-form">
						<label class="col-sm-2 control-label">状态：</label>
						<div class="col-sm-9">
							<?php if(!isset($info['status'])){ $info['status'] = 1; }; ?>
							<input name="status" value="1" type="radio" {if condition="$info.status eq '1'"}checked{/if} title="正常">
							<input name="status" value="0" type="radio" {if condition="$info.status eq '0'"}checked{/if} title="禁用">
						</div>
					</div>

					{foreach $level_rows as $key=>$vo }
					<div class="form-group">
						<input type="hidden" name="level_id" value="{$vo['id']}" />
						<label class="col-sm-2 control-label">{$vo['name']}分成：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" level_id="{$vo['id']}" value="" name="commission_rate" class="form-control" placeholder="请输入{$vo['name']}分成金额">
						</div>
					</div>
					{/foreach}
				<!-- form end -->
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="row btn-group-m-t">
				<div class="col-sm-9 col-sm-offset-1">
					<button type="button" class="btn btn-primary" onclick="CodeInfoDlg.add()" id="ensure">
						<i class="fa fa-check"></i>&nbsp;确认提交
					</button>
					<button type="button" class="btn btn-danger" onclick="CodeInfoDlg.close()" id="cancel">
						<i class="fa fa-eraser"></i>&nbsp;取消
					</button>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="__PUBLIC__/static/js/upload.js" charset="utf-8"></script>
<script src="__PUBLIC__/static/js/plugins/layui/layui.js" charset="utf-8"></script>
<script>
layui.use(['form'],function(){});
laydate.render({elem: '#create_time',type: 'datetime',trigger:'click'});
var CodeInfoDlg = {
	CodeInfoData: {},
	validateFields: {
		vip_name: {
			validators: {
				notEmpty: {
					message: '名称不能为空'
	 			},
	 		}
	 	},
		price: {
			validators: {
				notEmpty: {
					message: '价格不能为空'
	 			},
	 		}
	 	},
		days: {
			validators: {
				notEmpty: {
					message: '有效时长不能为空'
	 			},
	 		}
	 	},
	 }
}

CodeInfoDlg.collectData = function () {
	this.set('id').set('vip_name').set('price').set('days').set('wxapp_id').set('create_time').set('exchange_num');
};

CodeInfoDlg.add = function () {
	 this.clearData();
	 this.collectData();
	 if (!this.validate()) {
	 	return;
	 }
	 var status = $("input[name = 'status']:checked").val();
	 var ajax = new $ax(Feng.ctxPath + "/VipSys/add", function (data) {
	 	if ('00' === data.status) {
	 		Feng.success(data.msg,1000);
	 		window.parent.CodeGoods.table.refresh();
	 		CodeInfoDlg.close();
	 	} else {
	 		Feng.error(data.msg + "！",1000);
		 }
	 })

	 var commission_money_json = [];
	 $('input[name="commission_rate"]').each(function(){
	 //	console.log(this.value, $(this).attr('level_id'));
	 	commission_money_json.push({"id":$(this).attr('level_id'), "money":this.value})
	 });
	 //console.log(commission_money_json);
	 ajax.set('commission_money_json', commission_money_json);
	 ajax.set('status',status);
	 ajax.set(this.CodeInfoData);
	 ajax.start();
};


</script>
<script src="__PUBLIC__/static/js/base.js" charset="utf-8"></script>
{/block}
